import Http from "@/libs/Http";
import wxPromisify from "@/libs/wxPromisify";


export function sendSmsCode(phone) {
  return Http.post('/quanying-service-provider-portal/register/RegisterController/sendSmsCode.action', {
    mobile: phone,
  })
}

export async function getAppletOpenId() {
  try {
    let loginRes = await wxPromisify.login();
    console.log('loginRes:', loginRes);
    let code = loginRes.code;
    console.log('code:', code);
    if (code) {
      let GetAppletOpenId = await Http.post('/quanying-service-provider-system/appletsLogin/LoginAppletsController/GetAppletOpenId.action', {code});
      return GetAppletOpenId;
    }
  } catch (e) {
    console.log(e);
  }
}
//查看业务员是否登录过
export async function CheckLoginByCode() {
  try {
    let loginRes = await wxPromisify.login();
    console.log('loginRes:', loginRes);
    let code = loginRes.code;
    console.log('code:', code);
    if (code) {
      let tokenOrNull = await Http.post('/quanying-service-provider-system/appletsLogin/LoginAppletsController/CheckLoginByCode.action', {code});
      return tokenOrNull;
    }
  } catch (e) {
    console.log(e);
  }
}
//查看业务员是否登录过
export async function CheckLoginByCode1() {
  try {
    let loginRes = await wxPromisify.login();
    console.log('loginRes:', loginRes);
    let code = loginRes.code;
    console.log('code:', code);
    if (code) {
      let tokenOrNull = await Http.post('/quanying-service-provider-system/appletsLogin/LoginAppletsController/CheckLoginByCode1.action', {code});
      return tokenOrNull;
    }
  } catch (e) {
    console.log(e);
  }
}

export function authBindOpenId(code, openId) {
  return Http.post('/quanying-service-provider-system/appletsLogin/LoginAppletsController/AuthBindOpenId.action', {
    code, openId
  })
}

export function loginByPhone(mobile, smscode) {
  return Http.post('/quanying-service-provider-portal/register/RegisterController/appletsLoginByPhone.action', {
    mobile, smscode
  })
}

export function appletsCheckPhoneToken(token) {
  return Http.post('/quanying-service-provider-portal/register/RegisterController/appletsCheckPhoneToken.action', {
    token
  })
}


export function loginByAdmin(param) {
  return Http.post('/quanying-service-provider-system/appletsLogin/LoginAppletsController/loginByAdmin.action', param)
}
export function loginByAdmin1(param) {
  return Http.post('/quanying-service-provider-system/appletsLogin/LoginAppletsController/loginByAdmin1.action', param)
}